#define SPECTRUM_LEFT 0
int bands[7];
float weights[7] = {0.10,
                    0.15,
                    0.15,
                    0.20,
                    0.15,
                    0.15,
                    0.10};


void initSpectrum(){
  digitalWrite(SPECTRUM_STROBE,LOW);
    delay(1);
  digitalWrite(SPECTRUM_RESET,HIGH);
    delay(1);
  digitalWrite(SPECTRUM_STROBE,HIGH);
    delay(1);
  digitalWrite(SPECTRUM_STROBE,LOW);
    delay(1);
  digitalWrite(SPECTRUM_RESET,LOW);
    delay(5);
}

float getWeightedAmplitude(){
  byte index = 0;
  float amplitude = 0;
  for(index=0;index <7; index++)
  {
    bands[index] = analogRead(SPECTRUM_LEFT);
    delay(1);
    bands[index] += analogRead(SPECTRUM_LEFT);
    digitalWrite(SPECTRUM_STROBE,HIGH);
    digitalWrite(SPECTRUM_STROBE,LOW);
    amplitude += bands[index] * weights[index];
  }
  
  return amplitude;
}

float getHigherAmplitude(){
  byte index = 0;
  float higherAmplitude = 0;
  for(index=0;index <7; index++)
  {
    bands[index] = analogRead(SPECTRUM_LEFT);
    delay(1);
    bands[index] += analogRead(SPECTRUM_LEFT);
    bands[index] /= 2;
    if (bands[index] > higherAmplitude){
      higherAmplitude = bands[index];
    }
    digitalWrite(SPECTRUM_STROBE,HIGH);
    digitalWrite(SPECTRUM_STROBE,LOW);
    
  }
  
  return higherAmplitude;
}

float filterAmplitude(float amplitude){
  float outAmp = 0;
  outAmp = (amplitude - 170) / 800;
  outAmp = min(1, outAmp);
  outAmp = max(0, outAmp);
  return outAmp;
  
}
